// var mysql = require('mysql');
const express = require('express');
const fs = require('fs');
const bodyParser = require('body-parser');
const path = require('path');

const {
	test,
	addEmployeeInfo,
	getEmployeeList,
	updateEmployeeInfo,
	deleteEmployeeInfo,
	getEmployeeById,
	getEmployeeByName
} = require('./api/user');

const app = express();
// 处理静态文件 以及解析常见的请求格式URL编码和JSON 限制大小10mb 防止Ddos
app.use(express.static(path.join(__dirname, 'dist')));

app.use(express.urlencoded({
	extended: true,
	limit: "10mb"
}));
app.use(express.json({
	extended: true,
	limit: "10mb"
}));
// 跨域 路由处理之前
app.all('*', function(req, res, next) {
	res.header("Access-Control-Allow-Origin", "*");
	res.header('Access-Control-Allow-Headers',
		'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
	res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
	res.header("X-Powered-By", ' 3.2.1')
	res.header("Content-Type", "application/json;charset=utf-8");
	next();
});


//测试
app.get('/test', test);
app.get('/getEmployeeList', getEmployeeList);
app.get('/getEmployeeById/:id', getEmployeeById);
app.get('/getEmployeeByName/:name', getEmployeeByName);
app.post('/addEmployeeInfo', addEmployeeInfo);

app.put('/updateEmployeeInfo/:id', updateEmployeeInfo);
app.delete('/deleteEmployeeInfo/:id', deleteEmployeeInfo);










const {
	POST
} = require("./utils/config.js")
//服务器监听
app.listen(POST, () => {
	console.log(`服务器启动成功：http://localhost:${POST}`);
})